/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import com.sun.lwuit.Form;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import view.additional.CellItem;
import view.additional.ThumbList;
import view.additional.TickerRenderer;

/**
 *
 * @author Kvest
 */
public class ArchiveOrdersList extends Form implements ActionListener
{
    public static final int SHOW_ID = 1;
    public static final int BACK_ID = 2;
    public static final int MESSAGES_ID = 3;
    public static final int DELETE_ID = 4;

    private Command show;
    private Command back;
    private Command messages;
    private Command delete;

    private FormAction listener;
    
    //Список заказов
    private ThumbList ordersList;

    public ArchiveOrdersList(FormAction listener)
    {
        super("Архив заказов");
        this.listener = listener;

        init();
    }

    private void init()
    {
        setLayout(new BorderLayout());
        setScrollable(false);

        addCommandListener(this);

        back= new Command("Назад", BACK_ID);
        addCommand(back);

        delete= new Command("Удалить", DELETE_ID);
        addCommand(delete);

        messages= new Command("Сообщения", MESSAGES_ID);
        addCommand(messages);

        show= new Command("Показать", SHOW_ID);
        addCommand(show);

        //Создаем и настраиваем список
        ordersList = new ThumbList();
        ordersList.setSelectCommandText("");
        ordersList.setFixedSelection(ThumbList.FIXED_NONE_CYCLIC);
        TickerRenderer render = new TickerRenderer();
        render.setTickerEnabled(ViewManager.getViewManager().getFunctionMenuType() != FunctionMenu.KIROVOGRAD_TYPE);
        render.getStyle().setPadding(Component.BOTTOM, 0);
        render.getStyle().setPadding(Component.TOP, 0);
        ordersList.setRenderer(render);
        ordersList.getStyle().setPadding(Component.BOTTOM, 0);
        ordersList.getStyle().setPadding(Component.TOP, 0);
        addComponent(BorderLayout.CENTER,ordersList);
    }

    public void actionPerformed(ActionEvent evt)
    {
        if (listener != null)
        {
            listener.commandAction(evt.getCommand().getId());
        }
    }

    public void clear()
    {
        while (ordersList.size() > 0)
        {
            ordersList.getModel().removeItem(0);
        }
    }

    public void add(CellItem item)
    {
        ordersList.getModel().addItem(item);
    }

    public CellItem getSelectedItem()
    {
        return (CellItem)ordersList.getSelectedItem();
    }
}
